<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>7.2ES6基础-变量的解构赋值</title>
</head>
<body>
  <script>
    let arr = [3,4,5,6,7]
    let a = arr[0],b=arr[1],c=arr[2]
    console.log(arr)
    console.log(a,b,c)
    // 将数组
    // arr[0]赋值给a1
    // arr[1]赋值给a2
    // arr[2]赋值给a3
    // arr[3...n]赋值给a4
    let [a1,a2,a3,...a4] = arr
    console.log(a1,a2,a3)
    console.log(a4)
    let obj = {
      userName: "张用",
      age: 16
    }
    let {userName,age}=obj
    // userName = obj.userName
    // age = obj.age
    console.log(userName,age)
    let c1 = [3,4]
    let c2 = [5,6]
    let c3 = [c1[0],c1[1],c2[0],c2[1]]
    console.log(c3)
    let c4 = [...c1,...c2]
    console.log(c4)
    let d1 = {
      userName: '李四',
      age: 20
    }
    let d2 = {
      id: 1
    }
    let d3 = {...d1,...d2}
    console.log(d3)
  </script>
</body>
</html>